home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / gnugraph.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  6.9 KB  |  278 lines

  1. /* GNUPLOT -- gnugraph.trm */
  2. /*
  3.  * Copyright (C) 1993
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *  GNU plot(5) graphics language
  21.  *
  22.  * AUTHORS
  23.  *  Tony Richardson from the unixplot.trm by Colin Kelley, Thomas Williams,
  24.  *  and Russell Lang and from post.trm by Russell Lang.
  25.  * 
  26.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  27.  */
  28.  
  29. /*
  30.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  31.  */
  32.  
  33. /*
  34.  * This version of the 'unixplot' driver produces device independent
  35.  * output.  I've chosen parameter values so that the PostScript output
  36.  * produced by plot2ps is 5" x 3".  You can use the 'set size' command
  37.  * to get output up to 8.25" x 8.25", i.e. size values larger than
  38.  * 1 are okay.
  39.  */
  40.  
  41. /*
  42. Unixplot library writes to stdout.  A fix was put in place by
  43. ..!arizona!naucse!jdc to let set term and set output redirect
  44. stdout.  All other terminals write to outfile.
  45. */
  46.  
  47. /* This is a device independent format, so the output should look
  48.  * look "reasonable" on any output device.  I set things up there so
  49.  * that the output of plot2ps is 5" x 3" (standard GNUPLOT size).
  50.  * You can use GNUPLOT's size command to obtain plots to almost the
  51.  * 8.25" x 8.25" limit.
  52.  */
  53.  
  54. #ifndef GOT_DRIVER_H
  55. #include "driver.h"
  56. #endif
  57.  
  58. #ifdef TERM_REGISTER
  59. register_term(unixplot)
  60. #endif
  61.  
  62. #ifdef TERM_PROTO
  63. TERM_PUBLIC void UP_options __P((void));
  64. TERM_PUBLIC void UP_init __P((void));
  65. TERM_PUBLIC void UP_graphics __P((void));
  66. TERM_PUBLIC void UP_text __P((void));
  67. TERM_PUBLIC void UP_linetype __P((int linetype));
  68. TERM_PUBLIC void UP_move __P((unsigned int x, unsigned int y));
  69. TERM_PUBLIC void UP_vector __P((unsigned int x, unsigned int y));
  70. TERM_PUBLIC void UP_put_text __P((unsigned int x, unsigned int y, char str[]));
  71. TERM_PUBLIC int UP_text_angle __P((int ang));
  72. TERM_PUBLIC int UP_justify_text __P((enum JUSTIFY mode));
  73. TERM_PUBLIC void UP_reset __P((void));
  74. #define UP_XMAX 19859
  75. #define UP_YMAX 11565
  76. /* UP_VCHAR = ((UP_FONTSIZE*UP_YMAX)/(UP_YINCHES*72)) 
  77.             = UP_FONTSIZE*UP_VFONTSC
  78.    UP_HCHAR = ((UP_FONTSIZE/2)*UP_XMAX)/(UP_XINCHES*72))
  79.             = UP_FONTSIZE*UP_HFONTSC
  80. */
  81.  
  82. #define UP_VFONTSC  53.5
  83. #define UP_VCHAR    535   /* 10 * VFONTSC */
  84. #define UP_HFONTSC  27.6
  85. #define UP_HCHAR    276   /* 10 * HFONTSC */
  86.  
  87. #define UP_VTIC (UP_YMAX/80)
  88. #define UP_HTIC (UP_XMAX/80)
  89. #endif /* TERM_PROTO */
  90.  
  91. #ifndef TERM_PROTO_ONLY
  92. #ifdef TERM_BODY
  93.  
  94.  
  95. char up_font[MAX_ID_LEN+1] = "Courier" ; /* name of font */
  96. int up_fontsize = 10;
  97.  
  98. /* plot2ps produces a 8.25" x 8.25" square. */
  99. #define UP_SCREENX 32768
  100. #define UP_SCREENY 32768
  101. #define UP_SCRXINC 8.25
  102. #define UP_SCRYINC 8.25
  103.  
  104. /* We want a 5" x 3" graph by default. */
  105. #define UP_XINCHES 5
  106. #define UP_YINCHES 3
  107. /* UP_XMAX = (UP_SCREENX*UP_XINCHES)/UP_SCRXINC
  108.    UP_YMAX (UP_SCREENY*UP_YINCHES)/UP_SCRYINC */
  109.  
  110. #define UP_XLAST (UP_XMAX - 1)
  111. #define UP_YLAST (UP_YMAX - 1)
  112.  
  113. /* These offsets center plot2ps output in the middle of the page.  The
  114.  * amount of resizing that can be done is limited. */
  115. /*
  116.  * #define UP_XOFF 6454
  117.  * #define UP_YOFF 10601
  118.  */
  119.  
  120. /* These offsets give a 1" offset from the lower left corner.  This
  121.  * gives a greater range of permissible values in GNUPLOT's size
  122.  * command. */
  123. #define UP_XOFF 3972
  124. #define UP_YOFF 3972
  125.  
  126. enum JUSTIFY up_justify=LEFT;
  127.  
  128. TERM_PUBLIC void UP_options()
  129. {
  130.     if(!END_OF_COMMAND) {
  131.       if(almost_equals(c_token,"d$efault")) {
  132.         strcpy(up_font,"Courier");
  133.         up_fontsize = 10;
  134.         term->v_char = (unsigned int)(up_fontsize*UP_VFONTSC);
  135.         term->h_char = (unsigned int)(up_fontsize*UP_HFONTSC);
  136.         c_token++;
  137.       }
  138.     }
  139.  
  140.         if (!END_OF_COMMAND && isstring(c_token)) {
  141.                 quote_str(up_font,c_token, MAX_ID_LEN);
  142.                 c_token++;
  143.         }
  144.  
  145.         if (!END_OF_COMMAND) {
  146.                 /* We have font size specified */
  147.                 struct value a;
  148.                 up_fontsize = (int)real(const_express(&a));
  149.                 term->v_char = (unsigned int)(up_fontsize*UP_VFONTSC);
  150.                 term->h_char = (unsigned int)(up_fontsize*UP_HFONTSC);
  151.         }
  152.  
  153.     sprintf(term_options,"\"%s\" %d",up_font,up_fontsize);
  154. }
  155.  
  156. TERM_PUBLIC void UP_init()
  157. {
  158.     openpl();
  159.     space(0,0,UP_SCREENX-1,UP_SCREENY-1);
  160.     fontname(up_font);
  161.     fontsize(up_fontsize);
  162. }
  163.  
  164.  
  165. TERM_PUBLIC void UP_graphics()
  166. {
  167.     erase();
  168. }
  169.  
  170.  
  171. TERM_PUBLIC void UP_text()
  172. {
  173.     /* Flush here so that output will be complete. */
  174.     fflush(stdout);
  175. }
  176.  
  177.  
  178. TERM_PUBLIC void UP_linetype(linetype)
  179. int linetype;
  180. {
  181. static char *lt[2+5] = {"solid", "longdashed", "solid", "dotted","shortdashed",
  182.     "dotdashed", "longdashed"};
  183.  
  184.     if (linetype >= 5)
  185.         linetype %= 5;
  186.     linemod(lt[linetype+2]);
  187. }
  188.  
  189.  
  190. TERM_PUBLIC void UP_move(x,y)
  191. unsigned int x,y;
  192. {
  193.     move(x+UP_XOFF,y+UP_YOFF);
  194. }
  195.  
  196.  
  197. TERM_PUBLIC void UP_vector(x,y)
  198. unsigned int x,y;
  199. {
  200.     cont(x+UP_XOFF,y+UP_YOFF);
  201. }
  202.  
  203.  
  204. TERM_PUBLIC void UP_put_text(x,y,str)
  205. unsigned int x,y;
  206. char str[];
  207. {
  208.     UP_move(x,y); /* Don't adjust x and y! It's done in UP_move. */
  209.     switch(up_justify) {
  210.      case LEFT:
  211.       alabel('l','c',str);
  212.       break;
  213.      case CENTRE:
  214.       alabel('c','c',str);
  215.       break;
  216.      case RIGHT:
  217.       alabel('r','c',str);
  218.       break;
  219.     }
  220.  
  221. }
  222.  
  223. TERM_PUBLIC int UP_text_angle(ang)
  224. int ang;
  225. {
  226.     rotate(0,0,90*ang);
  227.     return TRUE;
  228. }
  229.  
  230. TERM_PUBLIC int UP_justify_text(mode)
  231. enum JUSTIFY mode;
  232. {
  233.     up_justify=mode;
  234.     return TRUE;
  235. }
  236.  
  237. TERM_PUBLIC void UP_reset()
  238. {
  239.     closepl();
  240. }
  241.  
  242. #endif /* TERM_BODY */
  243.  
  244. #ifdef TERM_TABLE 
  245.  
  246. TERM_TABLE_START(unixplot_driver)
  247.     "unixplot", "GNU plot(1) format [\042fontname\042 font_size]",
  248.        UP_XMAX, UP_YMAX, UP_VCHAR, UP_HCHAR,
  249.        UP_VTIC, UP_HTIC, UP_options, UP_init, UP_reset,
  250.        UP_text, null_scale, UP_graphics, UP_move, UP_vector,
  251.        UP_linetype, UP_put_text, UP_text_angle,
  252.        UP_justify_text, line_and_point, do_arrow, set_font_null
  253. TERM_TABLE_END(unixplot_driver)
  254.  
  255. #undef LAST_TERM
  256. #define LAST_TERM unixplot_driver
  257.  
  258. #endif /* TERM_TABLE */
  259. #endif /* TERM_PROTO_ONLY */
  260.  
  261. /*
  262.  * NAME: unixplot
  263.  *
  264.  * OPTIONS: font (default Courier) fontsize (default 10)
  265.  *
  266.  * SUPPORTS: GNU plot graphics language
  267.  *
  268.  * Further Info: From top of file:
  269.  *
  270.  * This version of the 'unixplot' driver produces device independent
  271.  * output.  I've chosen parameter values so that the PostScript output
  272.  * produced by plot2ps is 5" x 3".  You can use the 'set size' command
  273.  * to get output up to 8.25" x 8.25", i.e. size values larger than
  274.  * 1 are okay.
  275.  * 
  276.  * There is also a terminal (unixplot) for the non-GNU version but
  277.  * that can only be compiled if this one is left out.
  278.  */